home *** CD-ROM | disk | FTP | other *** search
- /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Awn-notif.
- *
- * The Initial Developer of the Original Code is
- * Thesa aka Florian Birée
- * Portions created by the Initial Developer are Copyright (C) 2007
- * the Initial Developer. All Rights Reserved.
- *
- * Portions of code are from the Thunderled extension.
- * The Initial Developer of Thunderled is
- * leo1981 (Leonardo Prosperi).
- * Portions created by Leonardo Prosperi are Copyright (C) 2007
- * Leonardo Prosperi. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
- var strings;
- var noReading;
- var error;
- var manyMails;
- var oneMail;
- var inbox;
-
- var AwnNotif = {
- consoleService: Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService),
-
- onLoad: function() {
- this.initialized = true;
- strings = document.getElementById("awn-notif-strings");
- noReading = strings.getString('noReading');
- error = strings.getString('error');
- manyMails = strings.getString('manyMails');
- oneMail = strings.getString('oneMail')
- inbox = strings.getString('inbox');
- },
-
- onClose: function() {
- this.initialized = true;
- AwnNotif.number(0);
- },
-
- number: function(x){
- try {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
- } catch (e) {
- alert(noReading);
- }
- var file = Components.classes["@mozilla.org/file/local;1"]
- .createInstance(Components.interfaces.nsILocalFile);
-
- const DIR_SERVICE = new
- Components.Constructor("@mozilla.org/file/directory_service;1","nsIProperties");
- try {
- path=(new DIR_SERVICE()).get("ProfD", Components.interfaces.nsIFile).path;
- } catch (e) {
- alert(error);
- }
- path = path + "/extensions/{761e13a8-9891-ef56-a4ee-988fa1bd8bbd}/content/awn-notif.py";
- file.initWithPath(path);
- if (x == 1){
- var args = [x, oneMail];
- } else {
- var args = [x, manyMails];
- }
- var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
- process.init(file);
- process.run(false, args, args.length);
- },
-
- folderListener: {
- OnItemAdded: function(parentItem, item, view){
- try {
- var mitem = item.QueryInterface(Components.interfaces.nsIMsgDBHdr);
- }
- catch(e) {return;}
- var folder = mitem.folder;
- while(folder.prettyName!=inbox && folder.rootFolder!=folder.parentMsgFolder){folder=folder.parentMsgFolder;}
- AwnNotif.number(folder.getNumUnread(true) + 1);
- },
- OnItemRemoved: function(parentItem, item, view){
- },
- OnItemPropertyChanged: function(item, property, oldValue, newValue) {
- },
- OnItemIntPropertyChanged: function(item, property, oldValue, newValue) {
- },
- OnItemBoolPropertyChanged: function(item, property, oldValue, newValue) {
- },
- OnItemUnicharPropertyChanged: function(item, property, oldValue, newValue){
- },
- OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) {
- var folder = item.folder;
- while(folder.prettyName!=inbox && folder.rootFolder!=folder.parentMsgFolder){folder=folder.parentMsgFolder;}
- if (property=="Status"){
- if (!item.isRead){
- AwnNotif.number(folder.getNumUnread(true) + 1);
- } else {
- AwnNotif.number(folder.getNumUnread(true) - 1);
- }
- }
-
- },
- OnItemEvent: function(folder, event){
- while(folder.prettyName!=inbox && folder.rootFolder!=folder.parentMsgFolder){folder=folder.parentMsgFolder;}
- AwnNotif.number(folder.getNumUnread(true));
- }
- },
-
- mailSession: '',
- notifyFlags: ''
- };
-
- window.addEventListener("load", function(e) { AwnNotif.onLoad(e); }, false);
- window.addEventListener("close", function(e) { AwnNotif.onClose(e); }, false);
-
- AwnNotif.mailSession = Components.classes["@mozilla.org/messenger/services/session;1"].getService(Components.interfaces.nsIMsgMailSession);
- AwnNotif.notifyFlags = Components.interfaces.nsIFolderListener.all;
- AwnNotif.mailSession.AddFolderListener(AwnNotif.folderListener, AwnNotif.notifyFlags);
-